package cn.yudao.org.service.impl;

import cn.yudao.basic.utils.PageList;
import cn.yudao.org.domain.Department;
import cn.yudao.org.mapper.DepartmentMapper;
import cn.yudao.org.query.DepartmentQuery;
import cn.yudao.org.service.IDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
* @Description: TODO 部门表的实现类
* @Author: Mr.Jia
* @Version: 1.0
* @Date:  2022/6/21 19:00
*/
@Service
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
public class DepartmentServiceImpl implements IDepartmentService {

    @Autowired
    private DepartmentMapper departmentMapper;

    /**
    * @Title: findAllDepartment
    * @Description: TODO 查询部门所有信息
    * @Author: Mr.Jia
    * @Version: 1.0
    * @Date:  2022/6/21 18:55
    * @Parameters:
    * @Return
    */
    public List<Department> findAllDepartment() {
        return departmentMapper.findAllDepartment();
    }

    /**
    * @Title: findByIdDepartment
    * @Description: TODO 根据id
    * @Author: Mr.Jia
    * @Version: 1.0
    * @Date:  2022/6/21 18:56
    * @Parameters:
    * @Return
    */
    @Override
    @Transactional
    public Department findByIdDepartment(Long id) {
        return departmentMapper.findByIdDepartment(id);
    }

    /**
    * @Title: addDepartment
    * @Description: TODO 往部门表中添加数据
    * @Author: Mr.Jia
    * @Version: 1.0
    * @Date:  2022/6/21 18:57
    * @Parameters:
    * @Return
    */
    @Override
    @Transactional
    public void addDepartment(Department department) {
        departmentMapper.addDepartment(department);
    }

    /** 
    * @Title: uptDepartment 根据id修改部门表中的数据
    * @Description: TODO
    * @Author: Mr.Jia
    * @Version: 1.0
    * @Date:  2022/6/21 18:58  
    * @Parameters: Department部门的实体类
    * @Return 
    */
    @Override
    @Transactional
    public void uptDepartment(Department department) {
        departmentMapper.uptDepartment(department);
    }

    /**
    * @Title: removeDepartment
    * @Description: TODO 根据id删除部门表中的某条数据
    * @Author: Mr.Jia
    * @Version: 1.0
    * @Date:  2022/6/21 18:59
    * @Parameters: id
    * @Return
    */
    @Override
    @Transactional
    public void removeDepartment(Long id) {
        departmentMapper.removeDepartment(id);
    }

    /**
    * @Title: queryDepartment 返回高级查询以及分页查询的数
    * @Description: TODO
    * @Author: Mr.Jia
    * @Version: 1.0
    * @Date:  2022/6/21 18:59
    * @Parameters:   Department部门的实体类
    * @Return PageList 封装当前页数据和总条数的类
    */
    @Override
    public PageList<Department> queryDepartment(DepartmentQuery departmentQuery) {
        // 查询当前页数据
        List<Department> rows = departmentMapper.queryDepartment(departmentQuery);
        // 查询当前页条数
        Integer total = departmentMapper.pagecount(departmentQuery);

        return new PageList<Department>(total, rows);
    }
}
